package zunge.twidel.typo;

import zunge.tools.StringDistance;

public class TypoCheck {
	
	public static final int TYPE_NORMAL = 0;
	public static final int TYPE_TYPO = 1;
	public static final int TYPE_REPOST = 2;
	
	public static final int T = 2;
	
	/**
	 * Get type(Normal/Typo/Repost) of a tweet, comparing to some previous tweet.
	 * 
	 * @param curr
	 * @param prev
	 * @return
	 */
	public static int typoCheck(String curr, String prev){
		if(curr == null || prev == null){
			return -1;
		}
		
		String cur = TweetCleaner.remove(curr);
		String pre = TweetCleaner.remove(prev);
		if(cur.equals(pre)){
			return TYPE_REPOST;
		}
		
		cur = TweetCleaner.abReorder(cur);
		pre = TweetCleaner.abReorder(pre);
		if(cur.equals(pre)){
			return TYPE_REPOST;
		}
		
		cur = TweetCleaner.replace(curr);
		pre = TweetCleaner.replace(prev);
		if(StringDistance.distance(cur, pre) <= T){
			return TYPE_TYPO;
		}
		
		return TYPE_NORMAL;
		
		/*
		 * label  getProperty(tweet1, tweet2)
        <1>    Remove all "#tag",  remove all "@username", replace all URLs using "URL", 
                  if tweet1 == tweet2, return REPOST
        <2>    Tokenize,  reorder the tokens subject to alphabets, 
                  if tweet1 == tweet2,  return REPOST
        <3>    Remove all "#",  replace all "@username" using "USER", replace all URLs using "URL",  
                  If edit distance (tweet1, tweet2)  <= T ,  return TYPO
		 */
	}
}
